package com.foxhorse.androidpractice.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.foxhorse.androidpractice.R;
import com.foxhorse.androidpractice.entity.MainMenu;

import java.util.List;

/**
 * Created by fanyang on 2017/6/8.
 */

public class MainMenuAdapter extends BaseAdapter {
    private Context context;
    private List<MainMenu> list;

    public MainMenuAdapter(Context context, List<MainMenu> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (null == convertView) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_gridview_main_activity, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tvDes.setText(list.get(position).getDes());
        return convertView;
    }

    class ViewHolder {
        private TextView tvDes;

        ViewHolder(View view) {
            tvDes = (TextView) view.findViewById(R.id.tv_des);
        }
    }
}
